package dao;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import util.Utilities;

import dto.AddressDTO;
import dto.FileListDTO;
import dto.MemberDTO;
import dto.PrivacyDTO;
import dto.PropertyDTO;
import dto.RefundDTO;
import dto.RoomDTO;
import dto.postScriptDTO;


public class postScriptDAO {
	private SqlMapClientTemplate sqlMap;
	public postScriptDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap=sqlMap;
	}
	public void insertContent(postScriptDTO pdto)throws SQLException{
		sqlMap.insert("insertContent",pdto);
	}
	public int updateNo()throws SQLException{
		return (Integer) sqlMap.queryForObject("updateNo");
	}
	public ArrayList<postScriptDTO> getAllMemberList() {
		return (ArrayList<postScriptDTO>) sqlMap.queryForList("getAllMemberList");
	}
	public int delete(int no) {
		return sqlMap.delete("delete",no);
	}
	public postScriptDTO selectContentByNO(int no) {
		return (postScriptDTO) sqlMap.queryForObject("getContent",no);
		
		
	}
	//ID로 사진파일명 검색
	public postScriptDTO selectPictureMemberById(String postScript_memberid){
		return (postScriptDTO)sqlMap.queryForObject("searchPicture",postScript_memberid);
	}
	public String selectPictureMemberById2(String postScript_memberid){
		return (String) sqlMap.queryForObject("searchPicture",postScript_memberid);
	}
	//postScript테이블 아이디로 memberTable의 파일명 검색
	public postScriptDTO selectPictureCons(String postScript_memberid){
		return (postScriptDTO)sqlMap.queryForObject("searchPictureCons",postScript_memberid);
	}
	public int updateContent(postScriptDTO pdto) {
		return sqlMap.update("updateContent",pdto);
	}
	public void insertContent(MemberDTO mdto)throws SQLException{
		sqlMap.insert("registerMember",mdto);
	}
	public ArrayList<postScriptDTO> getMemberList(String postScript_memberid) {
		return (ArrayList<postScriptDTO>) sqlMap.queryForList("getMemberList",postScript_memberid);
	}
	
	public ArrayList<postScriptDTO> getContentByRoom(int roomno) {
		return (ArrayList<postScriptDTO>) sqlMap.queryForList("getContentByRoom",roomno);
	}
	public RoomDTO roombyvalue(int roomno) {
		System.out.println("dao에서 처리합니다."+roomno);
		return (RoomDTO) sqlMap.queryForObject("roombyvalue",roomno);
	}
	public ArrayList<postScriptDTO> postbyvalue(int roomNo) {
		return (ArrayList<postScriptDTO>)sqlMap.queryForList("postbyvalue",roomNo);
	}
	public MemberDTO memberbyvalue(String memberId) {
		return (MemberDTO)sqlMap.queryForObject("memberbyvalue",memberId);
	}
	public ArrayList<postScriptDTO> selectBoardListByPage(int page,int postScript_roomno) {
		int perpage = Utilities.CONTENT_PER_PAGE;
		HashMap map = new HashMap();
		map.put("page",page);
		map.put("perpage",perpage);
		map.put("postScript_roomno",postScript_roomno);
		System.out.println(map);
		ArrayList<postScriptDTO> list =  (ArrayList<postScriptDTO>) sqlMap.queryForList("selectBoardListByPage",map);
		return list;
	}
	public int selectTotalContent(int postScript_roomno) {
		return (Integer) sqlMap.queryForObject("selectTotalContent",postScript_roomno);
	}
	public String filebyvalue(int roomno) {
		return (String) sqlMap.queryForObject("filebyvalue",roomno);
	}
	public String privacybyvalue(int roomno) {
		return (String)sqlMap.queryForObject("privacybyvalue",roomno);
	}
	public String propertybyvalue(int roomno) {
		return (String) sqlMap.queryForObject("propertybyvalue",roomno);
	}
	public String refundbyvalue(int roomno) {
		return (String) sqlMap.queryForObject("refundbyvalue",roomno);
	}
	public AddressDTO addressbyvalue(int roomno) {
		return (AddressDTO) sqlMap.queryForObject("addressbyvalue",roomno);
	}
	public ArrayList<FileListDTO> selectFileListByRoomNo(int roomno) {
		return (ArrayList<FileListDTO>)sqlMap.queryForList("selectFileListByRoomNo", roomno);
	}
	public String selectRoomnoByFileName(String filename) {
		return (String)sqlMap.queryForObject("selectRoomnoByFileName",filename);
	}
}